package com.example.util.common;


import org.springframework.data.keyvalue.core.IdentifierGenerator;
import org.springframework.data.util.TypeInformation;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @author Simon
 * @version 0.1
 * @application 主键生成策略
 */
public class UuidGenerator implements IdentifierGenerator {

    public static String generatorUuid() {
        String uuid = UUID.randomUUID().toString();
        uuid = uuid.replace("-", "");
        String id = uuid + "-" + new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
        return id.toUpperCase();
    }

    public static void main(String[] args) {
        System.out.println(generatorUuid());
    }

    @Override
    public <T> T generateIdentifierOfType(TypeInformation<T> typeInformation) {
        return (T) generatorUuid();
    }
}
